package com.adan.content.controller;

import com.adan.base.valid.ValidationGroups;
import com.adan.content.model.dto.BindTeachplanMediaDto;
import com.adan.content.model.dto.TeachplanDto;
import com.adan.content.model.po.Teachplan;
import com.adan.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author adan
 */
@Api(value = "课程计划编辑接口", tags = "课程计划编辑接口")
@Slf4j
@RestController
@RequestMapping("teachplan")
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;

    @ApiOperation("查询课程计划树形结构")
    @GetMapping("/{courseId}/tree-nodes")
    public List<TeachplanDto> queryTeachPlanTreeNode(@PathVariable Long courseId){
        return teachplanService.queryTeachPlanTreeNode(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping()
    public void saveTeachplan(@Validated({ValidationGroups.Insert.class, ValidationGroups.Update.class})
                                  @RequestBody Teachplan teachplan) {
        teachplanService.saveTeachplan(teachplan);
    }

    @ApiOperation("课程计划删除")
    @DeleteMapping("/{teachplanId}")
    public void deleteTeachplan(@PathVariable Long teachplanId) {
        teachplanService.deleteTeachplan(teachplanId);
    }

    @ApiOperation("课程计划排序")
    @PostMapping("/{moveType}/{teachplanId}")
    public void orderByTeachplan(@PathVariable String moveType, @PathVariable Long teachplanId) {
        teachplanService.orderByTeachplan(moveType, teachplanId);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation("课程计划解除媒资信息绑定")
    @DeleteMapping("/association/media/{teachPlanId}/{mediaId}")
    public void unAssociationMedia(@PathVariable Long teachPlanId, @PathVariable String mediaId) {
        teachplanService.unAssociationMedia(teachPlanId, mediaId);
    }
}
